package com.le.tester.tip.timedtask.scheduledexecutor;

import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;

/**
 * createTime：2022/10/13 14:23
 * description：使用ScheduledExecutorService进行轮询任务
 */
public class ScheduledExecutorDemo {
    private AtomicLong addCount = new AtomicLong(0L);

    public static void main(String[] args) {

        new ScheduledExecutorDemo().f1();
    }

    public void f1() {
        //感觉可行
        ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
        try {
            executorService.scheduleAtFixedRate(new Task(), 0L, 500, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            System.out.println("current position is finally");
        }
    }
}

